import 'dart:async';

import 'package:flutter/services.dart';

class Scanner {
  static const String channelName = 'guoran.red.scanner/plugin';
  static EventChannel eventChannel = const EventChannel(channelName);
  static StreamSubscription? subscription;

  static void init(onEvent) {
    subscription = eventChannel.receiveBroadcastStream().listen(onEvent);
  }

  static Future<void> dispose() async {
    if (subscription != null) {
      await subscription!.cancel();
    }
  }
}
